<?php

namespace Api\Openapi;

/**
 * Class Credit
 * @package Api\Openapi
 * @description 征信服务sdk
 *
 * 使用示范
 *
 * i. 查询征信记录黑名单
 *
 * $sdk = new \Api\Openapi\Credit();
 * $result = $sdk->queryBlackList('01', '321322********5436', '*常宝', array("mobile" => '158*********', "card_no" => '3234324234******'));
 */

class Credit {

    const URI_CREDIT_BLACKLIST = '/credit/blacklist/query';
    const URI_CRDIT_HRBB = '/credit/hrbb/query';

    /**
     * 查询交易记录
     *
     * @param string $cert_type 01-身份证
     * @param string $cert_no 证件号码
     * @param string $name 用户姓名
     * @param array $options
     *
     * @return mixed
     */
    public function queryBlackList($cert_type, $cert_no, $name, array $options = array()) {
        $body = array(
            'cert_type' => $cert_type,
            'cert_no' => $cert_no,
            'name'    => $name,
            "options" => $options,
        );
        $param = array(
            'header' => array(),
            'body'   => $body,
        );

        $result = Util::request(self::URI_CREDIT_BLACKLIST, $param);

        return $result["body"];
    }

    /**
     * 哈行征信查询
     *
     * @param $report_type 报文类型
     * @desc "ICR",  //个人信用报告  "ECR",  //企业信用报告
     *
     * @param $name 姓名
     * @param $cert_type 身份证类型
     * @param $cert_no 省份证号码
     * @param $reason 查询原因
     * @desc
     * *******个人查询原因****************
     *       "01I",  //贷后管理
     *       "02I",  //贷款审批
     *       "03I",  //信用卡审批
     *       "05I",  //异议核查
     *       "08I",  //担保资格审查
     *       "16I",  //公积金提取复核
     *       "19I",  //特约商户实名审查
     *       "22I",  //法人代表、负责人、高管等资信审查
     *       "23I",  //客户准入资格审查",
     *********企业信用报告查询原因*********
     *       "01E",  //贷前审查
     *       "02E",  //贷中操作
     *       "03E",  //贷后管理
     *       "04E",  //其他理由
     *       "05E",  //关联查询"
     * @param null $strategy 查询策略 默认3
     * @desc 1,  //只查本地
     *       2,  //只查人行
     *       3,  //先查本地,再查询人行"
     * @param null $auth_flag 客户授权标志 默认Y
     * @desc  "Y",  //已授权
     *        "N",  //未授权
     * @param null $loan_card_pwd 卡密码 默认''
     *
     * @return array
     * @throws Exception
     */
    public function queryHrbb($report_type, $name, $cert_type, $cert_no, $reason, $strategy = null, $auth_flag = null, $loan_card_pwd = null) {

        $body = array(
            'report_type' => $report_type,
            'name' => $name,
            'cert_type' => $cert_type,
            'cert_no'    => $cert_no,
            'reason' => $reason,
            'strategy' => $strategy,
            'auth_flag' => $auth_flag,
            'loan_card_pwd' => $loan_card_pwd,
        );
        $param = array(
            'header' => array(),
            'body'   => $body,
        );

        $result = Util::request(self::URI_CRDIT_HRBB, $param);

        return $result["body"];
    }
}